// vite.config.js
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import AutoImport from "unplugin-auto-import/vite";
import path from "path";
import VueSetupExtend from "vite-plugin-vue-setup-extend";
import svgLoader from 'vite-svg-loader';

import Components from 'unplugin-vue-components/vite'

import { VantResolver } from '@vant/auto-import-resolver'

export default defineConfig({
  plugins: [
    vue(),
    svgLoader(),
    vueJsx(),
    VueSetupExtend(),//devtools name名称
    AutoImport({
      dts: "src/auto-imports.d.ts",
      imports: ["vue"],
      resolvers: [VantResolver()],
    }),
    Components({
      // 自动导入 vant 组件
      resolvers: [VantResolver()],
      dts: false,
    }),
  ],
  base: "./", // 设置基本的 URL 路径
  publicDir: "public", // 设置公共文件夹的路径
  server: {
    host: '0.0.0.0',
    port: 8088, // 指定开发服务器的端口号
    open: true,//自动打开浏览器
    proxy: {
      "/api": {
        target: "",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""), // 重写请求路径
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      // "@": "/src", // 设置别名，方便导入模块
    },
  },
  optimizeDeps: {
    include: ["axios", "ant-design-vue"], // 指定需要预构建的依赖项
  },
  build: {
    outDir: "dist", // 设置输出目录
    assetsDir: "static", // 设置静态资源目录
    minify: true, // 是否压缩代码
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  define: {
    __VUE_PROD_DEVTOOLS__: true,
  }
});
